<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:22:"themes/admin/home.html";i:1568365182;}*/ ?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="/themes/admin/assets/css/layui.css">
  </head>
  <body>
    <div class="layui-tab layui-tab-brief" style="background: #FFFFFF;">
      <ul class="layui-tab-title">
        <li class="layui-this">导航菜单</li>
        <li>置顶推荐</li>
        <li>轮播图</li>
        <li>友情链接</li>
        <li>文章封面</li>
      </ul>
      <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
          <div class="layui-collapse" style ="width:400px;border:0">
            <?php if(!(empty($navList) || (($navList instanceof \think\Collection || $navList instanceof \think\Paginator ) && $navList->isEmpty()))): if(is_array($navList[0]) || $navList[0] instanceof \think\Collection || $navList[0] instanceof \think\Paginator): $i = 0; $__LIST__ = $navList[0];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
            <div id="<?php echo $vo['nav_id']; ?>">
              <div class="layui-colla-item">
                <h2 class="layui-colla-title"><?php echo $vo['nav_title']; ?></h2>
                <div class="layui-colla-content">
                  <input type="text" value="<?php echo $vo['nav_title']; ?>"  class="layui-input">
                  <input type="text" value="<?php echo $vo['url']; ?>"  class="layui-input">    
                  <input type="text" value="<?php echo $vo['order']; ?>"  class="layui-input"> 
                  <button onclick="saveNav(<?php echo $vo['nav_id']; ?>,this)" class="layui-btn layui-btn-normal layui-btn-sm" style="margin-top:10px;">
                    <i class="layui-icon">&#xe655;</i>保存
                  </button>
                  <button onclick="deleteNav(<?php echo $vo['nav_id']; ?> ,this,0)" class="layui-btn layui-btn-danger layui-btn-sm" style="margin-top:10px;">
                    <i class="layui-icon">&#xe640;</i>删除
                  </button>
                </div>
              </div>
              <!--子菜单开始-->
              <?php if(!(empty($navList[$vo['nav_id']]) || (($navList[$vo['nav_id']] instanceof \think\Collection || $navList[$vo['nav_id']] instanceof \think\Paginator ) && $navList[$vo['nav_id']]->isEmpty()))): if(is_array($navList[$vo['nav_id']]) || $navList[$vo['nav_id']] instanceof \think\Collection || $navList[$vo['nav_id']] instanceof \think\Paginator): $i = 0; $__LIST__ = $navList[$vo['nav_id']];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$v): $mod = ($i % 2 );++$i;?>
              <div class="layui-colla-item" style="margin-bottom:10px;margin-left:30px;">
                <h2 class="layui-colla-title"><?php echo $v['nav_title']; ?></h2>
                <div class="layui-colla-content">
                  <input type="text" name="title" value="<?php echo $v['nav_title']; ?>"  class="layui-input">
                  <input type="text" name="url" value="<?php echo $v['url']; ?>"  class="layui-input">
                  <button onclick="saveNav(<?php echo $v['nav_id']; ?>,this)"  class="layui-btn layui-btn-normal layui-btn-sm" style="margin-top:10px;">
                    <i class="layui-icon">&#xe655;</i>保存
                  </button>
                  <button onclick="deleteNav(<?php echo $v['nav_id']; ?> ,this,<?php echo $v['parent_id']; ?>)" class="layui-btn layui-btn-danger layui-btn-sm" style="margin-top:10px;">
                    <i class="layui-icon">&#xe640;</i>删除
                  </button>
                </div>
              </div>                         
              <?php endforeach; endif; else: echo "" ;endif; endif; ?>
              <!--子菜单结束-->
            </div>
            <?php endforeach; endif; else: echo "" ;endif; endif; ?>
          </div>
          <div style="margin-top:10px;">
            <form class="layui-form" action="">
              <div class="layui-input-inline">
                <select id="add-nav-parent">
                  <option value="">无父导航</option>
                   <?php if(!(empty($navList) || (($navList instanceof \think\Collection || $navList instanceof \think\Paginator ) && $navList->isEmpty()))): if(is_array($navList[0]) || $navList[0] instanceof \think\Collection || $navList[0] instanceof \think\Paginator): $i = 0; $__LIST__ = $navList[0];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
                  <option value="<?php echo $vo['nav_id']; ?>"><?php echo $vo['nav_title']; ?></option>
                  <?php endforeach; endif; else: echo "" ;endif; endif; ?>
                </select>
              </div>
              <div class="layui-input-inline">
                <input type="text" id="add-nav-title" placeholder="导航名称" class="layui-input">                          
              </div>
              <div class="layui-input-inline">
                <input type="text" id="add-nav-url" placeholder="导航URL" class="layui-input">                          
              </div>
              <button type="button" onclick="addNav()" class="layui-btn">
                <i class="layui-icon">&#xe608;</i> 添加
              </button>
            </form>
          </div>
        </div>
        <!--置顶推荐开始-->
        <div class="layui-tab-item">
          <form class="layui-form" action="">
            <div class="layui-form-item">
              <label class="layui-form-label">置顶文章</label>
              <div class="layui-input-inline">
                <input type="text" name="articleId" required value="<?php echo $topArticle['value']; ?>" autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">(请输入文章Id,用英文半角逗号隔开)</div>
            </div>                                                           
            <div class="layui-form-item">
              <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="btn-top-article">保存</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
              </div>
            </div>
          </form>
        </div>
        <!--置顶推荐结束-->
        <!--轮播图开始-->
        <div class="layui-tab-item">
         <form class="layui-form" action="">            
            <div class="layui-form-item">
              <label class="layui-form-label">轮播文章</label>
              <div class="layui-input-inline">
                <input type="text" name="articleId" required value="<?php echo $carousel['value']; ?>" autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">(请输入文章Id,用英文半角逗号隔开)</div>
            </div>                                                           
            <div class="layui-form-item">
              <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="carousel">保存</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
              </div>
            </div>
          </form>
          
        </div>
        <!--轮播图结束-->
        <div class="layui-tab-item">
          <table class="layui-table">
            <colgroup>
              <col width="150">
              <col width="200">
              <col>
            </colgroup>
            <thead>
              <tr>
                <th>ID</th>
                <th>链接名</th>
                <th>URL</th>
                <th>创建时间</th>
                <td>管理</td>
              </tr> 
            </thead>
            <tbody>
              <?php if(is_array($link) || $link instanceof \think\Collection || $link instanceof \think\Paginator): $i = 0; $__LIST__ = $link;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
              <tr>
                <td><?php echo $vo['link_id']; ?></td>
                <td><input type="text"  value="<?php echo $vo['link_title']; ?>" class="layui-input"></td>
                <td><input type="text"  value="<?php echo $vo['link_url']; ?>" class="layui-input"></td>
                <td><?php echo date("Y-m-d H:i:s",$vo['dataline']); ?></td>
                <td>
                  <div class="layui-btn-group">
                    <button onclick="editLink(<?php echo $vo['link_id']; ?>,this)" class="layui-btn layui-btn-primary">修改</button>
                    <button onclick="deleteLink(<?php echo $vo['link_id']; ?>,this)" class="layui-btn layui-btn-primary">删除</button>
                  </div>
                </td>
              </tr>
              <?php endforeach; endif; else: echo "" ;endif; ?>
              <tr>
                <td></td>
                <td><input id="link-title" type="text" class="layui-input"></td>
                <td><input id="link-url" type="text" class="layui-input"></td>
                <td></td>
                <td>
                  <div class="layui-btn-group">
                    <button onclick="addLink(this)" class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe608;</i> 添加</button>                   
                  </div>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
         <!--文章默认封面开始-->
        <div class="layui-tab-item">
          <img id="default-cover" style="width:150px;height:150px;" src="/uploads/default/default_cover.jpg" alt="请选择图片" ><br/>
          <button type="button" style="margin-top:10px;" class="layui-btn" id="subimt-default-cover">保存</button>
        </div>
        <!--文章默认封面结束-->
      </div>
    </div>
    <script src="/themes/admin/assets/layui.js"></script>
    <script src="/themes/admin/assets/jquery-3.2.1.min.js"></script>
    <script src="/static/js/common.js"></script>
    <script>
      layui.use('element');
      layui.use('layer');
      layui.use('form');
      //文章默认封面设置
        layui.use('upload', function(){
      var upload = layui.upload;
      var uploadInst = upload.render({
        elem: '#default-cover' //绑定元素
        ,url: '/admin/article/uploads' //上传接口
        ,auto:false
        ,field:'Image'
        ,bindAction: '#subimt-default-cover'
        ,data:{type:'defaultCover'}
        ,choose:function(obj){ 
           obj.preview(function(index, file, result){
             $("#default-cover").attr("src",result)
        });
        }
      });
    });
      //轮播图文章设置
      var topArticle = "<?php echo $topArticle['extend']; ?>";
      if(topArticle == 1){
        $("#topSwitch").attr("checked","checked");
      }
      layui.use('form', function(){
        var form = layui.form;
        form.on('submit(carousel)', function(data){  
          var value = data.field.articleId;
          $.ajax({
            type:"post",
            data:"value="+value,
            url:"/admin/system/carousel",
            success:function(e){
              if(e.code == 1){
                layer.msg(e.msg,{icon:1});
              }else{
                layer.msg(e.msg);
              }
            }
          });
          return false;
        });
      });
      //置顶文章设置
      var topArticle = "<?php echo $topArticle['extend']; ?>";
      if(topArticle == 1){
        $("#topSwitch").attr("checked","checked");
      }
      layui.use('form', function(){
        var form = layui.form;
        form.on('submit(btn-top-article)', function(data){  
          var value = data.field.articleId;
          $.ajax({
            type:"post",
            data:"value = "+value,
            url:"/admin/system/topArticle",
            success:function(e){
              if(e.code == 1){
                layer.msg(e.msg,{icon:1});
              }else{
                layer.msg(e.msg);
              }
            }
          });
          return false;
        });
      });
      //删除导航
      function deleteNav(navId,obj,parentId){
        if(parentId == 0){
          var ts = "该导航是父级导航，将一起删除其子导航？"
          }else{
            var ts = "确定删除？";
          }
        layer.msg(ts , {
          time: 0 //不自动关闭
          ,btn: ['删除', '取消']
          ,yes: function(index){
            $.ajax({
              type:"post",
              data:"navId="+navId,
              url:"/admin/system/deleteNav",
              success:function(e){
                if(e.code == 1){
                  if(parentId == 0){
                    self.location.reload();
                    $("#" +navId).remove();
                  }else{
                    $(obj).parents(".layui-colla-item").remove();
                  }
                  layer.msg("删除成功",{icon:1});
                }else{
                  layer.msg("删除失败");
                }
              }
            });
            layer.close(index);
          }
        });
      }

      //保存导航
      function saveNav(navId ,obj){
        var linkTitle = $(obj).parent("div").find("input").eq(0).val();
        var linkUrl = $(obj).parent("div").find("input").eq(1).val();
        var linkOrder = $(obj).parent("div").find("input").eq(2).val();
        $.ajax({
          type:"post",
          data:{
            nav_id:navId,
            nav_title:linkTitle,
            url:linkUrl,
            order:linkOrder            
          },
          url:"/admin/system/saveNav",
          success:function(e){
            if(e.code == 1){
              layer.msg(e.msg,{icon:1});
            }else{
              layer.msg(e.msg);
            }
          }
        });
      }

      //添加导航
      function addNav(){
        var navTitle = $("#add-nav-title").val();
        var navUrl = $("#add-nav-url").val();
        var navParent = $("#add-nav-parent option:selected").val();
        $.ajax({
          type:"post",
          data:"navTitle=" + navTitle + "&navUrl="+ navUrl + "&navParent=" +navParent,
          url:"/admin/system/addNav",
          success:function(e){
            if(e.code == 1){
               self.location.reload();
            }else{
              layer.msg(e.msg);
            }
          }
        });
      }
      //添加友情链接
      function addLink(obj){
        var linkTitle = $("#link-title").val();
        var linkUrl = $("#link-url").val();
        $.ajax({
          type:"post",
          data:"linkTitle=" + linkTitle + "&linkUrl="+ linkUrl,
          url:"/admin/system/addLink",
          success:function(e){
            if(e.code == 1){
              $(obj).parents("tr").before('<tr><td>'+e.data.id+'</td><td><input type="text"  value="'+e.data.title+'" class="layui-input"></td><td><input type="text"  value="'+e.data.url+'" class="layui-input"></td><td>'+datetime(e.data.dataline*1000)+'</td><td><div class="layui-btn-group"><button onclick="editLink('+e.data.id+',this)" class="layui-btn layui-btn-primary">修改</button><button onclick="deleteLink('+e.data.id+',this)" class="layui-btn layui-btn-primary">删除</button></div></td></tr>')
              layer.msg("添加成功",{icon:1});
            }else{
              layer.msg("添加失败");
            }
          }
        });
      }
      //修改友情链接
      function editLink(linkId,obj){
        var linkTitle = $(obj).parents('tr').find('input').eq(0).val();
        var linkUrl = $(obj).parents('tr').find('input').eq(1).val();
        $.ajax({
          type:"post",
          data:"linkId="+linkId + "&linkTitle=" + linkTitle + "&linkUrl="+ linkUrl,
          url:"/admin/system/editLink",
          success:function(e){
            if(e.code == 1){
              layer.msg("修改成功",{icon:1});
            }else{
              layer.msg("修改失败");
            }
          }
        });
      }
      //删除友情链接
      function deleteLink(linkId,obj)
      {
        layer.msg("确定删除？" , {
          time: 0 //不自动关闭
          ,btn: ['删除', '取消']
          ,yes: function(index){
            $.ajax({
              type:"post",
              data:"linkId="+linkId,
              url:"/admin/system/deleteLink",
              success:function(e){
                if(e.code == 1){
                  $(obj).parents('tr').remove();
                  layer.msg("删除成功",{icon:1});
                }else{
                  layer.msg("删除失败");
                }
              }
            });
            layer.close(index);
          }
        });              
      }
    </script>
  </body>
</html>
